﻿namespace KinonekoSoftware.CodariaDB.Runtimes.Categories
{
    partial class CatalogRoot
    {
        private const string ID_App_Startup = "App.Startup";
        private const string ID_App_Setting = "App.Setting";




        private const string ID_Compose  = "Compose.Root";
        private const string ID_Story    = "Story.Root";
        private const string ID_Timeline = "Timeline.Root";

        private const string ID_Rel = "Relationship";

        private const string ID_Tools                     = "Tools.Root";
        private const string ID_Tools_Prompts_Birthday    = "Tools.Prompts.Birthday";
        private const string ID_Tools_Prompts_Commissions = "Tools.Prompts.Commissions";

        private const string ID_Presentation = "Presentation.Root";


        private static void BuildOrder(ICollection<TreeCatalog> collection)
        {
            var map  = collection.ToDictionary(x => x.Id, x => x);
            var tree = new List<TreeCatalog>();

            foreach (var catalog in collection)
            {
                if (catalog.HasParent() && map.TryGetValue(catalog.ParentID, out var parent))
                {
                    catalog.Index = parent.Children.Count;
                    parent.Children.Add(catalog);
                }
                else if (catalog.IsRoot())
                {
                    catalog.Index = tree.Count;
                    tree.Add(catalog);
                }
            }
        }
    }
}